package com.itheima.controller;

import com.itheima.pojo.Brand;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/brands")
public class BrandController {

    //查询全部   http://localhost:8080/brands   get请求

    @GetMapping
    public List<Brand> findAll(){
        ArrayList<Brand> list = new ArrayList<>();
        Brand brand = new Brand();
        brand.setId(1);
        brand.setBrandName("300");
        brand.setCompanyName("ty");
        list.add(brand);
        list.add(brand);
        list.add(brand);
        return list;
    }

    //查询id  http://localhost:8080/brands/2  get请求
    @GetMapping("/{id}")
    public Brand findById(@PathVariable Integer id){
        Brand brand = new Brand();
        brand.setId(id);
        brand.setBrandName("300");
        brand.setCompanyName("ty");
        return brand;
    }

    //增加  http://localhost:8080/brands  post请求
    @PostMapping
    public String save(Brand brand){
        System.out.println(brand);
        return "ok";
    }

    //删除 http://localhost:8080/brands/2  delete请求
    @DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id){
        System.out.println("id= " + id);
        return "delete ok";
    }

    //修改 http://localhost:8080/brands  put请求
    @PutMapping
    public String update(@RequestBody Brand brand){
        System.out.println(brand);
        return "update ok";
    }
}
